Édition des propriétés des membres, à partir de l'annuaire, à nouveau possible.
[Plinn.git] / photoshop / Plinn Images Wizard.jsx
1 #target photoshop #include image_actions.jsxinc app.bringToFront(); $.localize = true; var messages = { "wizardTitle" : localize("$$$/JavaScripts/PlinnImageWizard/Title"), "srcPanelLabel" : localize("$$$/JavaScripts/PlinnImageWizard/SrcPanelLabel"), "helpPropsFile" : localize("$$$/JavaScripts/PlinnImageWizard/HelpPropsFile"), "buttonSelectPropsFile" : localize("$$$/JavaScripts/PlinnImageWizard/ButtonSelectPropsFile"), "noFileSelected" : localize("$$$/JavaScripts/PlinnImageWizard/NoFileSelected"), "promptSelectSrcPropsFile" : localize("$$$/JavaScripts/PlinnImageWizard/PromptSelectSrcPropsFile"), "helpSrcFolder" : localize("$$$/JavaScripts/PlinnImageWizard/HelpSrcFolder"), "selectSrcFolder" : localize("$$$/JavaScripts/PlinnImageWizard/ButtonSelectSrcFolder"), "promptSelectSrcFolder" : localize("$$$/JavaScripts/PlinnImageWizard/PromptSelectSrcFolder"), "destPanelLabel" : localize("$$$/JavaScripts/PlinnImageWizard/DestPanelLabel"), "helpDestFolder" : localize("$$$/JavaScripts/PlinnImageWizard/HelpDestFolder"), "selectDestFolder" : localize("$$$/JavaScripts/PlinnImageWizard/ButtonSelectDestFolder"), "promptSelectDestFolder" : localize("$$$/JavaScripts/PlinnImageWizard/PromptSelectDestFolder"), "noFolderSelected" : localize("$$$/JavaScripts/PlinnImageWizard/NoFolderSelected"), "okBtnLabel" : localize("$$$/JavaScripts/PlinnImageWizard/OkBtnLabel"), "cancelBtnLabel" : localize("$$$/JavaScripts/PlinnImageWizard/CancelBtnLabel") } function init() { dlg = null; propsFile = null; selectedPropsFile = null; srcFolder = null; selectedFolderPath = null; destFolder = null selectedDestFolderPath = null; gShortFileNameLength = 22; plinnFileProcess = {'loading_progress.psd':true, 'plinn.psd':true}; plinnFiles = null; colorRegistry = new Array(); } var colorRegistry = new Array(); colorRegistry['menuBAr'] var PlinnProcess = new Array(); PlinnProcess['loading_progress.psd'] = function(file) { var doc = app.open(file) app.activeDocument = doc; var fsPath = destFolder.fsName + '/loading_progress.gif'; _loadingProgress(fsPath, colorRegistry['memberActionsBoxBackground'], colorRegistry['bulletColor']) doc.close(SaveOptions.DONOTSAVECHANGES); }; PlinnProcess['plinn.psd'] = function(file) { var doc = app.open(file) app.activeDocument = doc; var fsPath = destFolder.fsName + '/logo.gif'; _plinnLogo(fsPath, colorRegistry['topbarBackgroundColor'], colorRegistry['bulletColor']) doc.close(SaveOptions.DONOTSAVECHANGES); }; function inputFileFilter(ob) { return (plinnFileProcess[ob.name]) ? true : false; } function setPropsFile() { propsFile = File.openDialog(messages['promptSelectSrcPropsFile']); if (!propsFile) return; selectedPropsFile.text = shortFileName(propsFile.fsName); parsePropsFile(); checkVarsInitialization(); } function setSrcFolder() { srcFolder = Folder.selectDialog(messages['promptSelectSrcFolder']); if (!srcFolder) return; selectedSrcFolderPath.text = shortFileName(srcFolder.fsName); plinnFiles = srcFolder.getFiles(inputFileFilter); checkVarsInitialization(); } function setDestFolder() { destFolder = Folder.selectDialog(messages['promptSelectDestFolder']); if (!destFolder) return; selectedDestFolderPath.text = shortFileName(destFolder.fsName); checkVarsInitialization(); } function checkVarsInitialization() { if (propsFile && srcFolder && destFolder) dlg.defaultElement.enabled = true; } function parsePropsFile() { propsFile.open('r'); var line, nameTypeValue, name, typeValue, type, value; while (!propsFile.eof) { line = propsFile.readln(); line = line.replace(/^\s*(.*?)\s*$/, "$1"); if (!line || line[0] == '#') continue; /* découpage */ nameTypeValue = line.split(':',2) name = nameTypeValue[0]; typeValue = nameTypeValue[1].split('=', 2); type = typeValue[0]; value = typeValue[1]; /* strip */ name = name.replace(/^\s*(.*?)\s*$/, "$1"); type = type.replace(/^\s*(.*?)\s*$/, "$1"); value = value.replace(/^\s*(.*?)\s*$/, "$1"); if (type != 'string' || value[0] != '#') continue; colorRegistry[name] = splitRGB(value); } } var hexToDec = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15}; function splitRGB(value) { value = value.slice(1) value = value.toLowerCase(); if (value.length == 3) value = value[0] + value[0] + value[1] + value[1] + value[2] + value[2] var r = value.slice(0,2); var g = value.slice(2, 4); var b = value.slice(4, 6); r = 16 * hexToDec[r[0]] + hexToDec[r[1]]; g = 16 * hexToDec[g[0]] + hexToDec[g[1]]; b = 16 * hexToDec[b[0]] + hexToDec[b[1]]; return [r, g, b]; } function processImages() { for (var i = 0 ; i < plinnFiles.length ; i++) PlinnProcess[plinnFiles[i].name](plinnFiles[i]); dlg.close(); } function drawDialog() { dlg = new Window('dialog', messages['wizardTitle']); /* Panneau de sélection des données source */ var panelSrc = dlg.add('panel', undefined, messages['srcPanelLabel']); /* Fichier de propriétés */ panelSrc.add('statictext', undefined, messages['helpPropsFile']); var propsFileGrp = panelSrc.add('group'); var btnChoosePropsFile = propsFileGrp.add('button', undefined, messages['buttonSelectPropsFile']); btnChoosePropsFile.onClick = setPropsFile; selectedPropsFile = propsFileGrp.add('statictext'); selectedPropsFile.text = messages['noFileSelected']; /* Sélection du dossier source */ panelSrc.add('statictext', undefined, messages['helpSrcFolder']); panelSrc.alignChildren = "left"; var folderSrcGroup = panelSrc.add('group'); var btnChooseSrcFolder = folderSrcGroup.add('button', undefined, messages['selectSrcFolder']); btnChooseSrcFolder.onClick = setSrcFolder; selectedSrcFolderPath = folderSrcGroup.add('statictext'); selectedSrcFolderPath.text = messages['noFolderSelected']; /* Panneau de sélection du dossier de destination */ var panelDest = dlg.add('panel', undefined, messages['destPanelLabel']); panelDest.add('statictext', undefined, messages['helpDestFolder']); panelDest.alignChildren = "left"; var folderDestGroup = panelDest.add('group'); var btnChooseDestFolder = folderDestGroup.add('button', undefined, messages['selectDestFolder']); btnChooseDestFolder.onClick = setDestFolder; selectedDestFolderPath = folderDestGroup.add('statictext'); selectedDestFolderPath.text = messages['noFolderSelected']; /* Boutons de contrôle */ var ctrlGrp = dlg.add('group'); ctrlGrp.alignement= 'right'; ctrlGrp.alignChildren = "right"; var okBtn = ctrlGrp.add('button', undefined, messages["okBtnLabel"]); okBtn.enabled = false; okBtn.onClick = processImages; dlg.defaultElement = okBtn; var cancelBtn = ctrlGrp.add('button', undefined, messages["cancelBtnLabel"]); dlg.cancelElement = cancelBtn; dlg.center(); dlg.show(); } function shortFileName( inFileName ) { if ( inFileName.length > gShortFileNameLength ) { return "..." + inFileName.substr( inFileName.length - gShortFileNameLength + 3, gShortFileNameLength - 3 ); } return inFileName; } function setSolidFillColor(color) { var r = color[0]; var g = color[1]; var b = color[2]; var id9 = charIDToTypeID( "setd" ); var desc4 = new ActionDescriptor(); var id10 = charIDToTypeID( "null" ); var ref1 = new ActionReference(); var id11 = stringIDToTypeID( "contentLayer" ); var id12 = charIDToTypeID( "Ordn" ); var id13 = charIDToTypeID( "Trgt" ); ref1.putEnumerated( id11, id12, id13 ); desc4.putReference( id10, ref1 ); var id14 = charIDToTypeID( "T " ); var desc5 = new ActionDescriptor(); var id15 = charIDToTypeID( "Clr " ); var desc6 = new ActionDescriptor(); var id16 = charIDToTypeID( "Rd " ); desc6.putDouble( id16, r ); var id17 = charIDToTypeID( "Grn " ); desc6.putDouble( id17, g ); var id18 = charIDToTypeID( "Bl " ); desc6.putDouble( id18, b ); var id19 = charIDToTypeID( "RGBC" ); desc5.putObject( id15, id19, desc6 ); var id20 = stringIDToTypeID( "solidColorLayer" ); desc4.putObject( id14, id20, desc5 ); executeAction( id9, desc4, DialogModes.NO ); } function main() { init(); drawDialog(); } try { main(); } catch(e) { alert(e); }